import pymysql

def execute_migrate(current_db_name,original_db_name,ip):
    db = pymysql.connect(ip,"root","root",current_db_name)

    cursor = db.cursor()

    try:
        sql = """SET FOREIGN_KEY_CHECKS=0;"""

        cursor.execute(sql)
        devsql = """insert into device(devSn,devName,devPlace,devIP,gateWay,netmask,lastSyncTime,macId,devVersion,
    devType,IdentifyType,memo,ipConfigType,isBind,bindTime,serviceId,attendType,startTime,isEnable) select devSn,devName,devPlace,
    devIP,gateWay,netmask,lastSyncTime,macId,devVersion,devType,IdentifyType,memo,ipConfigType,isBind,bindTime,serviceId,6,
    '2020-01-01 00-00-00',
    0 from """ + original_db_name + ".device;"
        cursor.execute(devsql)
        persql = """insert into personbase(personId,workSn,name,principalId,workTypeId,classOrderId,classTypeId,classTypeIdInWell,sex,bloodType,
    birthdate,workday,idCard,phone,address,zipcode,email,image,memo,eyeFlag,enrollTime,createTime,updateTime,deleteTime,irisStatus,passCard,modifyOperatorId,source,
    nation,password,alarmflag) select personId,workSn,name,principalId,workTypeId,classOrderId,classTypeId,classTypeIdInWell,sex,
    bloodType,birthdate,workday,idCard,phone,address,zipcode,email,image,memo,eyeFlag,enrollTime,createTime,updateTime,deleteTime,
    irisStatus,passCard,modifyOperatorId,source,nation,password,alarmflag from """ + original_db_name + ".personbase;"
        cursor.execute(persql)
        regsql = """insert into personrecogbase(personRecogId,personId,classTypeId,
    recogTime,recogType,devSn,devType,atPosition,opTime,operatorName,deleteTime,memo,attendState,isBlocked) select personRecogLogId as personRecogId,personId,
    classTypeId,recogTime,recogType,devSn,devType,atPosition,opTime,operatorName,deleteTime,memo,attendState,0 from """ + original_db_name + ".personrecogbase;"
        cursor.execute(regsql)
        irisdataSql = """insert into irisdatabaseextend(irisDataID,personID,eyePic,matchIrisCode,isoIrisData,isoImageType,isoImageFormat) select irisDataID,
    personID,eyePic,matchIrisCode,isoIrisData,isoImageType,isoImageFormat from ai1000server_cp125_original.irisdatabaseextend;"""
        cursor.execute(irisdataSql)
        irisdataESql = """insert into irisdatabase(irisDataID,personID,irisCode,devSn,
    eyeFlag,regTime,regPlace,createTime,updateTime,pupilRow,pupilCol,pupilRadius,irisRow,irisCol,irisRadius,focusScore,percentVisible,spoofValue,
    interlaceValue,qualityLevel,qualityScore,personType,saturation,img_height,img_width) select irisDataID,personID,irisCode,
    devSn,eyeFlag,regTime,regPlace,createTime,updateTime,pupilRow,pupilCol,pupilRadius,irisRow,irisCol,irisRadius,focusScore,
    percentVisible,spoofValue,interlaceValue,qualityLevel,qualityScore,personType,saturation,img_height,img_width from ai1000server_cp125_original.irisdatabase;"""
        cursor.execute(irisdataESql)

        sql = """SET FOREIGN_KEY_CHECKS=1;"""
        db.commit()
    except Exception as e:
        db.rollback()
        print(e)
    finally:
        cursor.close()
        db.close()

if __name__ == "__main__":
    inp = input("请按照顺序输入125、现在用的数据库名、ip地址用空格隔开：")
    arr = inp.split()
    execute_migrate(arr[0],arr[1],arr[2])

